﻿package com.rbac.system.config;

import com.rbac.system.service.PermissionInitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 应用启动监听器
 * 在应用启动时执行初始化操作
 */
@Component
public class ApplicationStartupListener implements ApplicationRunner {
    
    @Autowired
    private PermissionInitService permissionInitService;
    
    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            // 只检查并创建缺失的基础权限，不强制初始化
            permissionInitService.checkAndCreateMissingPermissions();
            System.out.println("✅ 基础权限检查完成");
        } catch (Exception e) {
            System.err.println("❌ 基础权限检查失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}


